package com.anxin.act.task.complete.impl;

import com.anxin.act.task.complete.TaskComplete;
import com.anxin.act.task.entity.WfActHiTask;
import com.anxin.act.task.service.AddTaskService;
import com.anxin.act.task.service.WfActHiCommentService;
import com.anxin.act.task.service.WfActHiTaskService;
import com.anxin.act.task.service.WfActRuTaskService;
import com.anxin.act.task.vo.TaskVo;
import com.anxin.act.utils.ActTaskUtils;
import com.anxin.act.utils.ActUtils;
import com.anxin.common.utils.sys.UserUtils;
import org.activiti.engine.impl.bpmn.behavior.ParallelMultiInstanceBehavior;
import org.activiti.engine.impl.pvm.process.ActivityImpl;
import org.activiti.engine.task.Task;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 后加签提交
 * @author: liuxiangyu
 * @date: 2020/4/26 16:22
 */
@Service
public class AddAfterCompleteImpl extends TaskComplete {

    @Autowired
    private AddTaskService addTaskService;

    @Autowired
    private WfActHiCommentService wfActHiCommentService;

    @Autowired
    private WfActHiTaskService wfActHiTaskService;

    @Autowired
    private WfActRuTaskService wfActRuTaskService;


    /**
     * 提交流程
     *
     * @param taskVo
     */
    public String complete(TaskVo taskVo){
        // 保存当前任务的审批记录
        WfActHiTask wfActHiTask = wfActHiCommentService.getHiTask(taskVo);
        wfActHiTaskService.save(wfActHiTask);

        wfActHiCommentService.addComment(taskVo,wfActHiTask.getId());
        wfActHiCommentService.addComment(taskVo.getActId(),wfActHiTask.getId(), "后加签:" + UserUtils.getNickNamesByUserArray(taskVo.getAddUser()));

        // 进行后加签
        wfActRuTaskService.addTask(taskVo);
        // 挂起流程
        addTaskService.hangTask(taskVo.getViewRuTask());

        return wfActHiTask.getId();
    }



}
